import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number
  uid: number
  weapon: string
  sub_weapon: string
  shoulder: string
  upper: string
  waist: string
  lower: string
  foot: string
  bracelet: string
  ring: string
  necklace: string
}

class user_equipment extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

user_equipment.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '自增主键'
    },
    uid: {
      type: DataTypes.BIGINT,
      allowNull: false,
      unique: true,
      comment: '用户uid'
    },
    weapon: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '武器'
    },
    sub_weapon: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '副武器'
    },
    shoulder: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '头肩'
    },
    upper: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '上身'
    },
    waist: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '腰部'
    },
    lower: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '下身'
    },
    foot: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '脚部'
    },
    bracelet: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '手镯'
    },
    ring: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '戒指'
    },
    necklace: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '项链'
    }
  },
  {
    sequelize,
    tableName: 'user_equipment',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      },
      {
        unique: true,
        fields: ['uid']
      }
    ]
  }
)

export { user_equipment }
